A5Storage::DataItem WriteToStream Method

Syntax

.WriteToStream as L (Data as System::IO::Stream, BYREF Length as N, BYREF ContentTypeResult as C)

Arguments

DataSystem::IO::Stream

The stream to which data is written.

BYREF LengthNumeric

The amount of data returned in the stream.

BYREF ContentTypeResultCharacter

The content type. E.g. "text/html"

Returns

ResultLogical

Returns .T. if the operation succeeds, otherwise .F. (see .CallResult for additional error information.)

Description

Retrieves the item data and writes it to a System::IO::Stream object. The content type and length written are also returned.

Discussion

You must dimension the resulting Stream and ContentType and Length variables prior to making the call.

Example

dim Stream as System::IO::Stream = null_value()
dim ContentType as C
dim Length as N
dim Buffer as B
dim CallResult as CallResult
dim Container as A5Storage::DataContainer = null_value()
dim Item as A5Storage::DataItem = null_value()

Stream = new System::IO::MemoryStream()
CallResult = A5Storage::DataContainer::Open(Container, "Provider='Disk';Container='c:\A5Webroot';")
if CallResult.Success
    if Container.ReferenceItem(Item, "Speak.a5w")
        if Item.WriteToStream(Stream, Length, ContentType)
            Stream.Seek(0, System::IO::SeekOrigin::Begin)
            dim Reader as System::IO::BinaryReader = new System::IO::BinaryReader(Stream)
            Buffer = Reader.ReadBytes(Length)
            Stream.close()
        else
            CallResult = Item.CallResult
        end if
    else
        CallResult = Container.CallResult
    end if
end if

if CallResult.Success	
    showvar("Type: " + ContentType + crlf() + "Length: " + Length + crlf(2) + buffer, "Success")
else
    showvar(CallResult.Text, "Error")
end if